//
//  JumpUtils.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2024/12/26.
//

import SwiftUI
/**
 * 所有的跳转试图，都写在这里，避免找不到对应的试图
 */
enum JumpType : String, CaseIterable, Identifiable {
    case SET_VIEW = "SET_VIEW"
    case AI_SET_VIEW = "AI_SET_VIEW"
    case ABOUT_VIEW = "ABOUT_VIEW"
    case WEB_VIEW = "WEB_VIEW" //web
    case USER_VIEW = "USER_VIEW" //用户信息
    case NOTIFY_VIEW = "NOTIFY_VIEW" //公告
    case FEEDBACK = "FEEDBACK" //意见反馈
    case MY_FEEDBACK = "MY_FEEDBACK" //我的意见反馈
    case DIARY = "DIARY" //日记
    case ADD_DIARY = "ADD_DIARY" //添加日记
    case WEEKLY_LETTER = "WEEKLY_LETTER" //每周来信
    case WEEKLY_LETTER_DETAIL = "WEEKLY_LETTER_DETAIL" //每周来信,详情
    case CALL_HISTORY = "CALL_HISTORY" //来电记录
    case VIP_VIEW = "VIP_VIEW" //vip
    case AI_ROLE = "AI_ROLE" //创建/编辑。心灵
    case BUY_COUNT = "BUY_COUNT" //购买次数
    case BUBBLE_SHOP = "BUBBLE_SHOP" //气泡商城
    case BUBBLE_MY = "BUBBLE_MY" //我的气泡
    case BUBBLE_DIARY = "BUBBLE_DIARY" //日记的评论气泡
    case CHAT_VIEW = "CHAT_VIEW" //聊天界面
    case MEMORY_DESC = "MEMORY_DESC" //记忆说明
    case INVITE_ACT = "INVITE_ACT" //邀请活动
    case AI_CUSTOM = "AI_CUSTOM"
    case AI_API_SITES = "AI_API_SITES"//api站点
    case AI_CUSTOM_CREATE = "AI_CUSTOM_CREATE"//新建api
    case AI_CUSTOM_ERROR = "AI_CUSTOM_ERROR"//API错误

    var id: String {
        self.rawValue
    }
}



/**
 * 跳转View
 */
struct jumpView: View {
    var data : Jump

    var body: some View {
        ZStack{
            switch data.type {
            case .SET_VIEW:
                SetView()
            case .AI_SET_VIEW:
                let from = data.getData(data.json, Int.self)
                AiSetView(from: AiSetView.FromType(rawValue: from ?? 0) ?? AiSetView.FromType.FROM_DEFAULT)
            case .AI_CUSTOM:
                AiCustomView2()
            case .WEB_VIEW:
                let jumpData = data.getData(data.json, JumpData.self)
                WebView(url: jumpData?.url ?? "about:blank",title: jumpData?.title)
            case .USER_VIEW:
                UserInfoView()
            case .NOTIFY_VIEW:
                NotifyView()
            case .FEEDBACK:
                let jumpData = data.getData(data.json, MsgBean.self)
                FeedbackView(bean: jumpData)
            case .MY_FEEDBACK:
                MyFeedbackView()
            case .DIARY:
                if let jumpData = data.getData(data.json, DiaryBean.self) {
                    DiaryView(bean: jumpData).autoID(data.id)
                }
            case .ADD_DIARY:
                //添加日记允许为空
                let jumpData = data.getData(data.json, DiaryBean.self)
                AddDiaryView(bean: jumpData)
            case .WEEKLY_LETTER:
                WeeklyLetterView()
            case .WEEKLY_LETTER_DETAIL:
                let jumpData = data.getData(data.json, WeeklyLetterBean.self)
                WeeklyLetterDetailView(bean: jumpData ?? WeeklyLetterBean()) {
                    pathManager.back()
                }
            case .CALL_HISTORY:
                CallHistoryiew()
            case .VIP_VIEW:
                VipView()
            case .BUBBLE_SHOP:
                BubbleShopView()
            case .BUBBLE_MY:
                let id = data.getData(data.json, String.self)
                MyBubbleView(roleId: id ?? "")
            case .BUBBLE_DIARY:
                let bean = data.getData(data.json, DiaryBean.self)
                MyBubbleCommentView(diaryBean: bean ?? DiaryBean(content: ""))
            case .AI_ROLE:
                let jumpData = data.getData(data.json, AiRoleBean.self)
                AiRoleView(bean: jumpData)
            case .BUY_COUNT:
                BuyAiCountHomeView()
            case .CHAT_VIEW:
                let jumpData = data.getData(data.json, ChatView.Param.self)
                ChatView(param: jumpData)
            case .MEMORY_DESC:
                AiSetMemoryDescView()
            case .INVITE_ACT:
                InviteActView()
            case .ABOUT_VIEW:
                Text("ABOUT_VIEW")
            case .AI_API_SITES:
                ApiSitesView()
            case .AI_CUSTOM_CREATE:
                let jumpData = data.getData(data.json, AiCustomBean.self) ?? AiCustomBean()
                AiCustomCreateView(bean: jumpData)
            case .AI_CUSTOM_ERROR:
                let jumpData = data.getData(data.json, AiCustomBean.self) ?? AiCustomBean()
                AiCustomErrorView(bean: jumpData)
            }
        }.autoID(data.id)
    }
}

